home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / AWNP / AWNP-Docs / Demos / dict-thesar.rx < prev    next >
Encoding:
Text File  |  2000-04-26  |  11.8 KB  |  438 lines

  1. /*Online dictionary and thesauris Vers 2.1
  2. This script uses the Meriam Webster site .
  3. www.m-w.com
  4. */
  5.  
  6. if ~show('L','rexxsupport.library') then
  7. if ~addlib('rexxsupport.library',0,-30,0) then
  8. exit(20)
  9.  
  10. nl='a'x
  11. delaybub=0
  12.  
  13. call setdefaults()
  14. call buildgui()
  15. do while ~eof(ca)
  16. if delaybub>0 then do
  17. delaybub=delaybub-1
  18. if delaybub=0 then do
  19. bubleon=newbub
  20. call topipe('bubble top 'bubx 'left 'buby 'gt "'help.newbub'"')
  21. end
  22. end
  23.   call topipe('tick 50')
  24.   in= readln(ca)
  25.  parse var in in1 in2 in3 in4 in5 .
  26.   if (in1='help' & helpon~=0 ) then do
  27. call bubble(in2)
  28. end
  29.   if in1='active' then call bubble(0)
  30.   if in1='key' then call key()
  31.   if in1='gadget' then call gadget()
  32.   if in1='iconify' then call iconify()
  33.   if in1='menu' then call menu()
  34.   if in1='close' then call windowclosed()
  35. end
  36. exit
  37.  
  38. key:
  39.  
  40. scrpos=topipe('id 'txtgad)
  41. if scrpos=oldpos then scrpos=scrpos-40
  42. if ((in2=77) & (scrpos<oldpos)) then scrpos=topipe('id 'txtgad' scroll' scrpos+80)
  43. if (in2=76) then do
  44. if (scrpos>79) then scrpos=topipe('id 'txtgad' scroll' scrpos-80)
  45. else scrpos=topipe('id 'txtgad' scroll 0' )
  46. end
  47. return
  48.  
  49. gadget:
  50. call bubble(0)
  51. if in2=wordgad then do
  52.   parse var in . . w .
  53.  call topipe('id 'lay1' dis 1 ref')
  54.  call topipe('id 'lay2' dis 1 ref')
  55. if level>0 then call topipe('id 'abortgad' dis 0 ref')
  56.   call trans()
  57.   call writeln(ca,'id 'txtgad' scroll -1 bd gt "'length(savetx)+1'"')
  58.   newpos=topipe(savetx)
  59.   call topipe('id 'txtgad' scroll 'oldpos)
  60.  call topipe('id 'lay1' dis 0 ref')
  61.  call topipe('id 'lay2' dis 0 ref')
  62.  call topipe('id 'abortgad' s 0 dis 1 ref')
  63.   oldpos=newpos
  64. end
  65. if in2=quitgad then exit
  66. if in2=levelgad then level=in3
  67. if in2=bookgad then book=in3
  68. if in2=cleargad then oldpos=topipe('id 'txtgad' gt ""')
  69. if in2=savegad then do
  70.   call writeln(ca,'id 'filegad' s 1 save 1 fn "'filename'"')
  71.   parse value readln(ca) with res1 '"' res2 '"'
  72.   if (res1>0) then do
  73.     filename=res2
  74.     call writeln(ca,'id 'txtgad' read')
  75.     len=readln(ca)
  76.     data=readch(ca,len)
  77.     if( open(out,res2,'W')) then do
  78.       call   writech(out,data)
  79.       call   close(out)
  80.     end
  81.   end
  82. end
  83. return
  84.  
  85. windowclosed:
  86. exit
  87. return
  88.  
  89. setdefaults:
  90. parse source . . called .
  91. oldpos=0
  92. level=0
  93. book=0
  94. filename=''
  95. scrpos=''
  96. prono=''
  97. theno=''
  98. envname='onlinedictionary'
  99. call getenv()
  100. abouttx='Online Dictionary & Thesaurus*nVers 1.1*nAuthor William Parker*nGUI by AWNPipe:'
  101. return
  102.  
  103. buildgui:
  104. call open(ca,"awnpipe:dict/xc")
  105. call topipe(' it "Dict Thesa" "Online Dictionary & Thesaurus" sk v defg ig h state m a 'window' ii "'called'"' )
  106. lay1=topipe(' layout weih 0')
  107. call topipe(' label gt "Word: " ua')
  108. wordgad=topipe('string chl lj')
  109. help.wordgad=' Enter word to look up '
  110. levelgad=topipe('chooser cl "First|Major|All" pu weiw 0')
  111. help.levelgad='Select look up depth*n First Entry*n Major Entries*n All Entries'
  112. bookgad=topipe('chooser cl "Dictionary|Thesaurus" pu weiw 0')
  113. help.Bookgad='Select book to search in*n Dictionary definition*n Thesaurus information'
  114. call topipe(' le')
  115. txtgad=topipe('textfield ro arrows')
  116. help.txtgad=' This area displays the retreived definitions. It is read only *n but you may drag and copy the results to the clipboard. *n The cursor keys can be used to scroll the information.'
  117. lay2=topipe(' layout weih 0')
  118. abortgad=topipe('button pb gt "Abort" dis 1')
  119. help.abortgad=' Abort multiple retreival*navailable for major and all*noptions'
  120. savegad=topipe('button gt "Save Log"')
  121. help.savegad=' Save retreived definitions to a file '
  122. cleargad=topipe('button gt "Clear Log"')
  123. help.cleargad=' Remove all retreived definitions '
  124. quitgad=topipe('button gt "Quit"')
  125. help.quitgad=' Quit the dictionary '
  126. call topipe(' layoutend')
  127. filegad=topipe('getfile save ua')
  128. men0gad= topipe('Menu gt "Project|Window|$@SSnapshot|$@UUnsnapshot|@AAbout|@H^&Bubble Help|-|@QQuit"')
  129. call pragma('W','N')
  130. if (showlist('A','MIAMI')|(showlist('P','MIAMI.1'))) then do
  131.   men1gad= topipe('Menu gt "Miami|Online|Offline|Status|Hide GUI|Show GUI|SSL Version 2|$On|$Off|-|Quit Miami"')
  132. miamifound=1
  133. end
  134. call pragma('W')
  135. call topipe("open")
  136. return
  137.  
  138. topipe:
  139. /* this routine does error checking on lines written to pipe.*/
  140. /*get line to output*/
  141. parse arg out
  142. /* write to the pipe*/
  143. call writeln(ca,out)
  144. /*get responce and parse it.*/
  145. res=readln(ca)
  146. parse var res res1 res2 res3
  147. /* if all is ok return the second part of the responce (usualy the GID)*/
  148. if res1='ok' then return(res2)
  149. /* something went wrong, we notify the user then exit */
  150. /*show problem line and responce (reponce may be just a blank line)*/
  151. say 'error from: 'out
  152. say '  responce: ' in
  153. exit
  154.  
  155. trans:
  156. if testtcp() then return
  157. savetx='0a'x||'---------------'||'0a'x
  158. newword=w
  159. call topipe('id 0 s 8 gt " Connecting for  'newword'"')
  160.  
  161. savew=w
  162. w=urlencode(w)
  163. if book=0 then t1='book=Dictionary&va='w
  164. else t1='book=Thesaurus&va='w
  165.  
  166. t2=length(t1)
  167. t2='Content-Length: 't2
  168. if open(net,'tcp:www.m-w.com/80') then do
  169. call topipe('id 0 s 8 gt " Getting information for  'newword'"')
  170. call writeln(net,"POST /cgi-bin/dictionary HTTP/1.0")
  171. call writeln(net,"User-Agent: MSIE/4.0; (Spoofed by AWNPdictthing (1.0 beta))")
  172. call writeln(net,"Accept: */*;q=1")
  173. call writeln(net,"Host: www.m-w.com")
  174. call writeln(net,t2)
  175. call writeln(net,"Content-Type: application/x-www-form-urlencoded")
  176. call writeln(net,"")
  177. call writeln(net,t1)
  178. call writeln(net,"")
  179. def=''
  180. do while ~eof(net)
  181.   if length(def)< 54000 then def=def||readch(net,10000)
  182. end
  183. call close(net)
  184. savedef=def
  185. call getdef()
  186. end
  187. else do
  188. savetx=savetx||'0a'x||'Connect Failed for 'newword||'0a'x
  189. call Showtx(0,"Could not connect to m-w.com")
  190. end
  191. return(0)
  192.  
  193. getdef:
  194. call topipe('id 0 s 8 gt " Parsing result for  'newword'"')
  195. if book=0 then parse var def 'Main Entry:' . '0a'x d1 '</form>'
  196. else parse var def 'Entry Word:' . '0a'x d1 '</form>'
  197. txt=htmltotx(d1)
  198. if txt='' then txt= 'not found'
  199. if book =0 then savetx=savetx||'0a'x||' (dict) >>>> 'newword' <<<<'||'0a0a'x||txt||'0a'x
  200. else savetx=savetx||'0a'x||' (thes) >>>> 'newword' <<<<'||'0a0a'x||txt||'0a'x
  201. if savedef~='' then call extradef()
  202. call topipe('id 0 s 8 gt " Online Dictionary & Thesaurus"')
  203.  
  204. return
  205.  
  206. showtx:
  207. call open(ptx,'awnpipe:kctxt/xc')
  208. call writeln(ptx,'db dg "Dictionary & Thesauris info" q cg cm v m a so si ')
  209. call writeln(ptx,'label lj gt "'arg(2)'"')
  210. if arg(1)=0 then call writeln(ptx,'button gt "O.K." close')
  211. call writeln(ptx,'open')
  212. if arg(1)~=0 then call writeln(ptx,'tick 'arg(1))
  213. else call writeln(ptx,'m')
  214. call close(ptx)
  215. return(0)
  216.  
  217. menu:
  218. if in2=1 then do
  219.   if in3=5 then do
  220.     if in4=0 then do
  221.       address command "echo yes >ENV:Miami/SSLVERSION2"
  222.       call showtx(200,' Miami SSL Version 2 on ')
  223.     end
  224.     else do
  225.       address command "echo no >ENV:Miami/SSLVERSION2"
  226.       call showtx(200,' Miami SSL Version 2 off ')
  227.     end
  228.     return()
  229.   end
  230.   if ~show('P','MIAMI.1') then do
  231.     if in3=1 | in3=1 | in3=6 then do
  232.       call showtx(200,' Miami is not running ')
  233.       return()
  234.     end
  235.     address command 'Run >NIL: Miami:Miami '
  236.     do 5 while ~show('P','MIAMI.1')
  237.       address command 'waitforport MIAMI.1'
  238.     end
  239.     if rc=5 then return()
  240.   end
  241.   if in3=1 | in3=6 then address MIAMI.1 'OFFLINE'
  242.   if in3=7 then address MIAMI.1 'QUIT'
  243.   if in3=0  then address MIAMI.1 'ONLINE'
  244.   if in3=3 then address MIAMI.1 'HIDE'
  245.   if in3=4 then address MIAMI.1 'SHOW'
  246.   if in3=2 | in3=0 | in3=1 then do
  247.     address MIAMI.1 'ISONLINE'
  248.     if rc then call showtx(400,' Miami is online ')
  249.     else call showtx(400,' Miami is offline ')
  250.   end
  251. end
  252.  
  253. if in2=0 then do
  254. if in3=0 then do
  255. if in4=0 then call setenvarc()
  256. if in4=1 then call unsetenvarc()
  257. end
  258. if in3=1 then call showtx(500,abouttx)
  259. if in3=2 then do
  260. helpon=in5
  261. if helpon=0 then call bubble(0)
  262. end
  263. if in3=4 then  exit
  264. end
  265. return()
  266.  
  267. iconify:
  268. if in2=1 then call topipe('id 0 s 32')
  269. else call topipe('id 0 s 64')
  270. call bubble(0)
  271. return
  272.  
  273. getenv:
  274. if(open(env,'env:'envname,'R')) then do
  275. windows=readln(env)
  276. filename=readln(env)
  277. call close(env)
  278. parse var windows wl wt ww wh .
  279. window= 'top' wt 'left' wl 'width' ww 'height' wh
  280. end
  281. else window='tl width 400 height 200'
  282. return
  283.  
  284. setenv:
  285. call writeln(ca,'id 0 read')
  286. windowr=readln(ca)
  287. parse var windowr wl wt ww wh .
  288. if (datatype(wt,N) &datatype(wl,N) &datatype(ww,N) & datatype(wh,N) ) then do
  289. call open(env,'env:'envname,'W')
  290. call writeln(env,windowr)
  291. call writeln(env,filename)
  292. call close(env)
  293. end
  294. return(0)
  295.  
  296. setenvarc:
  297. call setenv()
  298. address command 'copy env:'envname' envarc:'envname '>nil:'
  299. return
  300.  
  301. unsetenvarc:
  302. call setenv()
  303. if exists('envarc:'envname) then delete('envarc:'envname)
  304. if exists('env:'envname) then delete('env:'envname)
  305. return
  306.  
  307. testtcp:
  308. if miamifound='1' then do
  309. if (showlist('P','MIAMI.1')) then address MIAMI.1 'ISONLINE'
  310. else rc=0
  311.     if ~rc then do
  312. call showtx(0,'Miami is not online*n *nYou must be online to use *n the dictionary or thesauris.*n *nYou can start Mimai from the menus.')
  313. savetx=''
  314. return(1)
  315. end
  316. end
  317. call pragma('W','N')
  318. if ~showlist(H,'TCP') then do
  319. if miamifound=1 then call showtx(0,'You must be online to use*n the dictionary or thesauris.*n *nYou can start Mimai from the menus.')
  320. else call showtx(0,'Can not find TCP device*n *nYou must be online to use*n the dictionary or thesauris.')
  321. savetx=''
  322. call pragma('W')
  323. return(1)
  324. end
  325. call pragma('W')
  326. return(0)
  327.  
  328. bubble:
  329. newbub=arg(1)
  330. if newbub=-1 then newbub=0
  331. if (bubbleon=newbub) then return()
  332. if bubbleon~=0 then call  topipe('bubble')
  333. if newbub=0 then delaybub=0
  334. else do
  335. bubx=in3
  336. buby=in4
  337. delaybub=3
  338. end
  339. return
  340.  
  341. extradef:
  342. parse var savedef '<select name=jump size=3>' options '</select' . '<input type=hidden name=list value="' list '"'
  343. savedef=''
  344. if options='' then return(0)
  345. parse var options '>' newword '0a'x options
  346. do while options~=''
  347. call writeln(ca,'read id 'abortgad)
  348. if readln(ca)~=0 then do
  349. savetx=savetx||'0a'x||' OPERATION ABORTED !'||'0a'x
  350. return(0)
  351. end
  352. parse var options '>' newword '0a'x options
  353. if (level=0 ||(right(newword,1)~=']' & level=1)) then savetx=savetx' * 'newword
  354. else call transmore()
  355. end
  356. return(0)
  357.  
  358. transmore:
  359. if testtcp() then return
  360. call topipe('id 0 s 8 gt " Connecting for 'newword'"')
  361. if book=0 then t1='hdwd='savew'&book=Dictionary&jump='newword'&list='list
  362. else t1='hdwd='savew'&book=Thesaurus&jump='newword'&list='list
  363. t1=urlencode(t1)
  364. t2=length(t1)
  365. t2='Content-Length: 't2
  366. if open(net,'tcp:www.m-w.com/80') then do
  367. call topipe('id 0 s 8 gt " Getting information for 'newword'"')
  368. call writeln(net,"POST /cgi-bin/dictionary HTTP/1.0")
  369. call writeln(net,"User-Agent: MSIE/4.0; (Spoofed by AWNPdictthing (1.0 beta))")
  370. call writeln(net,"Accept: */*;q=1")
  371. call writeln(net,"Host: www.m-w.com")
  372. call writeln(net,t2)
  373. call writeln(net,"Content-Type: application/x-www-form-urlencoded")
  374. call writeln(net,"")
  375. call writeln(net,t1)
  376. call writeln(net,"")
  377. def=''
  378. do while ~eof(net)
  379.   if length(def)< 54000 then def=def||readch(net,10000)
  380. end
  381. call close(net)
  382. call getdef()
  383. end
  384. else do
  385. savetx=savetx||'0a'x||'>>Connect Failed for 'newword'<<'||'0a'x
  386. call Showtx(0,"Could not connect to m-w.com")
  387. options=''
  388. end
  389. return(0)
  390.  
  391. urlencode:
  392. uin=translate(arg(1),'+',' ')
  393. do while index(uin,';')>0
  394. parse var uin in1 ';' in2
  395. uin=in1||'%3B'||in2
  396. end
  397. do while index(uin,'=')>0
  398. parse var uin in1 '=' in2
  399. uin=in1||'%3D'||in2
  400. end
  401. do while index(uin,'[')>0
  402. parse var uin in1 '[' in2
  403. uin=in1||'%5B'||in2
  404. end
  405. do while index(uin,']')>0
  406. parse var uin in1 ']' in2
  407. uin=in1||'%5D'||in2
  408. end
  409. do while index(uin,',')>0
  410. parse var uin in1 ',' in2
  411. uin=in1||'%2C'||in2
  412. end
  413. return(uin)
  414.  
  415. htmltotx:
  416. d1=arg(1)
  417. d1=translate(d1,'  ','0a0d'x)
  418. dt=''
  419. do while index(d1,'<br>')>0
  420.   parse var d1 d2 '<br>' d1
  421.   dt=dt||d2||'0a'x
  422. end
  423. d1=dt||d1
  424. dt=''
  425. do while d1~=''
  426. parse var d1 d2 '<' . '>' d3 '<' . '>' d4 '<' . '>' d5 '<' . '>' d6 '<' . '>' d7 '<' . '>' d12 '<' . '>' d13 '<' . '>' d14 '<' . '>' d15 '<' . '>' d16 '<' . '>' d17 '<' . '>'  d22 '<' . '>' d23 '<' . '>' d24 '<' . '>' d25 '<' . '>' d26 '<' . '>' d27 '<' . '>' d32 '<' . '>' d33 '<' . '>' d34 '<' . '>' d35 '<' . '>' d36 '<' . '>' d37 '<' . '>' d1
  427. dt=dt||d2||d3||d4||d5||d6||d7||d12||d13||d14||d15||d16||d17||d22||d23||d24||d25||d26||d27||d32||d33||d34||d35||d36||d37
  428. end
  429. call open(fh,'awnpipe:dec/u/f','W')
  430. call writech(fh,dt)
  431. call close(fh)
  432. call open(fh,'awnpipe:dec','R')
  433. sel=readch(fh,64000)
  434. call close(fh)
  435. return(sel)
  436.  
  437.  
  438.